<?php
	class documentocompania extends Controller {
		public function __construct() {
			parent::Controller();
			$this->load->model('documentocompania2');
			$this->load->helper(array('form','url'));
			$this->load->library(array('upload','form_validation'));
			$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
		}

		function index() {
			$this->load->view('main', array('content_page' => 'documento_list','menutop' => 0));
		}
		
		function data() {
			$page = $this->input->post('page') ? $this->input->post('page') : 1; // Pagina Actual o 1 por default
			$sortname = $this->input->post('sidx') ? $this->input->post('sidx') : 'ID_airport'; // Columna para el order by
			$sortorder = $this->input->post('sord') ? $this->input->post('sord') : 'asc'; // Orden (asc|desc)
			$limit = $this->input->post('rows') ? $this->input->post('rows') : 10;
			$start = $limit * $page - $limit;
			if($start < 0) $start = 0;

			header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
			header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
			header("Cache-Control: no-cache, must-revalidate" );
			header("Pragma: no-cache" );

			$records = $this->documentocompania2->LoadStatusDocumento();

			$totalRecords = $this->documentocompania2->GetCount();

			$totalPages = ceil($totalRecords/$limit);
			if ($page > $totalPages) $page = $totalPages;

			$json_output = array(
				'page'		=> $page,
				'total'		=> $totalPages,
				'records'	=> $totalRecords,
				'rows'		=> array()
			);

			if($records != false) {
				foreach($records as $estatus) {
					    
					    $url = "<a href='http://company24h.com/modify/form/getData.php?url=".$estatus->getUrl().".csv'>Documento</a>";
					
					      $arr = $json_output['rows'][] = array(
					                                            'idDocumento' => $estatus->getIdDocumento(), 	
					                                            'numeroOrden' => $estatus->getNumeroOrden(), 
					                                            'referencia' => $estatus->getReferencia(),
					                                            'nombreContacto'=>$estatus->getNombreContacto(),
					                                            'telefono'=>$estatus->getTelefono(),
					                                            'email'=>$estatus->getEmail(),
					                                            'date'=>$estatus->getDate(),
					                                            'url'=>$url
					                                            ); 
				}
				
				
			}

			echo json_encode($json_output);
		}
	}
?>